<template>
	<view class="main codeLogin">
		<u--input placeholder="请输入账号" border="none" v-model="user" maxlength="11" type="number"
			customStyle="padding:20rpx;background:#f8f8f8" fontSize="16"></u--input>
		<view class="codeInput">
			<u--input placeholder="请输入密码" border="none" v-model="pwd" maxlength="6"
				customStyle="padding:20rpx;background:#f8f8f8;" fontSize="18;"></u--input>
		
		</view>
        <view style="margin-top:30rpx;"></view>
		<u-button type="primary" text="登录"  :loading="loading" @click="login"></u-button>

	</view>
</template>

<script>
	import {
		doUserLogin
	} from '@/api/api.js';
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {

		data() {
			return {
				loading: false,
				user: '',
				pwd: '',
			}
		},
		onLoad(options) {

		},

		methods: {
			...mapMutations(['userLogin', 'logout']),
			Vuexlogin(provider) {
				this.userLogin(provider)
				uni.navigateBack({
					delta: 3
				})
			},
			
			login() {
				let _this = this
				if (!_this.user) {
					uni.showToast({
						title: '请输入用户名',
						icon: 'none'
					})
				} else if (!_this.pwd) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
				} else {
                  doUserLogin({user:_this.user,pwd:_this.pwd}).then(r=>{
					   if(r.data.code==200){
						   uni.$u.toast('登录成功');
						   _this.Vuexlogin(r.data.data)
					   }else{
						   uni.$u.toast(r.data.msg);
					   }
				  })
				}
			}
		}
	}
</script>
<style scoped lang="scss">
	.main {
		padding: 40rpx;

		.phone {
			margin-top: 100rpx;
		}

		.codeInput {
			margin-top: 30rpx;
			position: relative;

			.sendCode {
				position: absolute;
				right: 20rpx;
				top: 50%;
				transform: translateY(-50%);
				color: $base-color;
				font-size: 28rpx;
			}
		}

	}
</style>